<template>
  <div class="audit-list">
    <tag-content-header search refresh @toolFun="toolFun" :settingData="columns">
      <template #title>
        <span>审核发布项列表</span>
      </template>
      <template #toolsPre>
        <el-radio-group v-model="listType">
          <el-radio label="selectWaitMyInfo">等我处理</el-radio>
          <el-radio label="selectMyReleaseInfo">我提交的</el-radio>
          <el-radio label="selectProcessedInfo">已处理</el-radio>
          <el-radio label="selectInfoAll">全部</el-radio>
        </el-radio-group>
      </template>
    </tag-content-header>
    <tag-table
      ref="table"
      @refresh="getList"
      :data="dataList"
      :columns="columns"
      :params="params"
      :total="totalSize"
      @rowClick="rowClick"
      :maxHeight="maxTableHeight"
    >
    </tag-table>
    <audit-drawer ref="auditDrawer" @callback="getList"></audit-drawer>
  </div>
</template>

<script>
import auditDrawer from './audit-drawer'
export default {
  components: {
    auditDrawer
  },
  data() {
    return {
      listType: 'selectWaitMyInfo',
      loading: false,
      dataList: [],
      columns: [
        {
          show: true,
          label: '审核标签名称',
          prop: 'auditName',
          search: true,
          searchKey: ''
        },
        {
          show: true,
          label: '审核项类别',
          prop: 'auditType',
          dict: '$audit_type',
          search: true,
          searchKey: '',
          searchType: 'select',
          align: 'center'
        },
        {
          show: true,
          label: '审核状态',
          prop: 'auditStatus',
          dict: '$audit_status',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '创建时间',
          prop: 'createTm',
          search: true,
          searchKey: '',
          searchType: 'daterange',
          align: 'center'
        },
        {
          show: true,
          label: '发布方',
          prop: 'publisherName',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '审核方',
          prop: 'auditorName',
          search: true,
          searchKey: '',
          align: 'center'
        }
      ],
      params: {
        ascs: [],
        descs: [],
        currentPageNum: 1,
        pageSize: 10,
        queryParams: {},
        descPriority: false
      },
      totalSize: 0
    }
  },
  watch: {
    listType() {
      this.getList()
    }
  },
  computed: {
    maxTableHeight() {
      // 表格最大高度 =  可视窗口高度 - 顶栏高度50 - 内容容器padding - 页面容器padding和border - 工具栏最小高度 - 描述框高度
      var paddingHeight = 0
      if (this.$route.meta.isTab) {
        paddingHeight = 70
      } else {
        paddingHeight = 30
      }
      var height = this.$store.state.common.documentClientHeight - 50 - paddingHeight - 80
      return height
    }
  },
  created() {
    this.getList()
  },
  methods: {
    rowClick(row) {
      if (row.auditId) {
        this.$refs.auditDrawer.showDrawer(row)
      }
    },
    getList() {
      this.loading = true
      this.$ajax({
        url: this.$ajax.setUrl(`tag/tagAuditCenter/${this.listType}`),
        method: 'get',
        params: this.$ajax.setParams(this.params)
      })
        .then(({ data }) => {
          if (data && data.code === '0') {
            if (data.data.currentPageNum === this.params.currentPageNum) {
              this.dataList = data.data.records
              this.totalSize = data.data.totalSize
            }
          } else {
            this.$message.error(data.data || data.msg)
          }
        })
        .finally(() => (this.loading = false))
    },
    toolFun(operation) {
      switch (operation) {
        case 'search':
          // 搜索动作
          this.$refs['table'].searchToggle()
          break
        case 'refresh':
          // 刷新动作
          this.getList()
          break
      }
    }
  }
}
</script>

<style lang="scss">
.audit-list {
  height: 100%;
  margin-left: 430px;
  padding: 20px;
  box-shadow: 1px 1px 3px #ddd, -1px -1px 3px #ddd;
  overflow: hidden;
  .el-radio {
    margin-right: 20px;
  }
  .el-table__row {
    cursor: pointer;
  }
}
</style>
